﻿Imports Control_Vuelos_BL
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraGrid.Views.Grid

Public Class frmConsultarViajeXTrabajador
    Inherits frmBaseMantenimiento

    Private WithEvents printableComponentLink1 As New PrintableComponentLink()
    Private ImageDir As String = "Resources\"
    Private Images As New Hashtable()
    Dim oPasajero As New PasajeroBL

    Private Sub frmConsultarViajeXTrabajador_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        SG_Control_Vuelos_Main.RibbonPageGroup1.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup2.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup3.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup4.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup5.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup6.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup7.Visible = True
        SG_Control_Vuelos_Main.RibbonPageGroup9.Visible = True
    End Sub

    Private Sub frmConsultarViajeXTrabajador_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BarBtnAgregar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnModificar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnEliminar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnCancelar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        BarBtnGrabar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        pr_Refresh()
        AddHandler BarBtnImprimir.ItemClick, AddressOf pr_Imprimir
        AddHandler BarBtnRefresh.ItemClick, AddressOf pr_Refresh
        AddHandler ConsultarViajeXTrabajador1.AdvBandedGridView1.CustomUnboundColumnData, AddressOf pr_CustomUnBoundColumnData
    End Sub

    Private Sub pr_CustomUnBoundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs)
        If e.Column.FieldName = "foto" Then
            Dim view As GridView = TryCast(sender, GridView)
            Dim fileName As String = "User.png"
            If (Not Images.ContainsKey(fileName)) Then
                Dim img As Image = Nothing
                Try
                    Dim filePath As String = DevExpress.Utils.FilesHelper.FindingFileName("E:\SG_Control_Vuelos\Control_Vuelos_GUI\", ImageDir & fileName, False)
                    img = Image.FromFile(filePath)
                Catch
                End Try
                Images.Add(fileName, img)
            End If
            e.Value = Images(fileName)
        End If
    End Sub

    Private Sub pr_Refresh()
        ConsultarViajeXTrabajador1.GridControl1.DataSource = oPasajero.pr_Reservas.Tables("Pasajero")
    End Sub

    Private Sub pr_Imprimir()
        Dim printingSystem1 As New PrintingSystem()
        printingSystem1.Links.AddRange(New Object() {printableComponentLink1})
        printableComponentLink1.Landscape = True
        ConsultarViajeXTrabajador1.GridControl1.Refresh()
        printableComponentLink1.Component = ConsultarViajeXTrabajador1.GridControl1
        printableComponentLink1.ShowPreviewDialog()
    End Sub

    Private Sub printableComponentLink1_CreateReportHeaderArea(ByVal sender As Object, ByVal e As DevExpress.XtraPrinting.CreateAreaEventArgs) Handles printableComponentLink1.CreateReportHeaderArea
        Dim brick As DevExpress.XtraPrinting.TextBrick
        brick = e.Graph.DrawString("Record de Viaje Por Persona", Color.Blue, New RectangleF(0, 0, 500, 40), DevExpress.XtraPrinting.BorderSide.None)
        brick.Font = New Font("Tahoma", 16)
        brick.StringFormat = New DevExpress.XtraPrinting.BrickStringFormat(StringAlignment.Center)
    End Sub

End Class